package net.cdsunrise.com.common.entity;


import net.cdsunrise.com.common.grantedauthority.SpringGrantedAuthority;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * 用户表
 * @author: LiuWei
 * @date: Create in 14:47 2018/05/09
 */
public class SysUser implements Serializable {

    private int id;

    private String username;
    private String password;

    private int age;

    private Set<SysRole> sysRoles = new HashSet<>();

    public Set<SpringGrantedAuthority> getAuthorities() {
        Set<SpringGrantedAuthority> userAuthotities = new HashSet<>();
        for (SysRole role : this.sysRoles) {
            for (SysResource sysResource : role.getSysResources()) {
                userAuthotities.add(new SpringGrantedAuthority(sysResource.getValue()));
            }
        }
        return userAuthotities;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Set<SysRole> getSysRoles() {
        return sysRoles;
    }

    public void setSysRoles(Set<SysRole> sysRoles) {
        this.sysRoles = sysRoles;
    }

}
